package com.heima.article.listener;

import com.alibaba.fastjson.JSONObject;
import com.heima.article.service.ApArticleConfigService;
import com.heima.model.common.enums.WmNewsMessageConstants;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import java.util.Map;

//@Component
@Slf4j
public class ArticleDownListener {
    @Autowired
    private ApArticleConfigService apArticleConfigService;

//    @KafkaListener(topics = WmNewsMessageConstants.WM_NEWS_UP_OR_DOWN_TOPIC)
    public void onMsg(String msg) {
        log.info("{}", msg);
        if (StringUtils.isNotBlank(msg)) {
            Map map = JSONObject.parseObject(msg, Map.class);
            apArticleConfigService.updateArticle(map);
        }

    }
}
